<?php

namespace app\admin\logic;

use app\admin\model\GgoodsProp;
use think\facade\Db;


class Orderlogic
{
    // 留值
    public static function setData($param)
    {

        $data=[
            'keywords'=>isset($param['keywords'])?$param['keywords']:'',
            'cid'=>isset($param['cid'])?$param['cid']:[],
            'mintime'=>isset($param['mintime'])?$param['mintime']:'',
            'maxtime'=>isset($param['maxtime'])?$param['maxtime']:'',
            'minmoney'=>isset($param['minmoney'])?$param['minmoney']:'',
            'maxmoney'=>isset($param['maxmoney'])?$param['maxmoney']:'',
        ];
        return $data;
    }

    // 拼接where条件
    public static function getWhere($param)
    {
        $where=[];
        if (isset($param['keywords']) && !empty($param['keywords'])){
            $where[]=['o.order_sn','like','%'.$param['keywords'].'%'];
        }
        if (isset($param['cid']) && $param['cid']<>''){
            $where[]=['o.status','in',$param['cid']];
        }
        if (isset($param['mintime']) && !empty($param['mintime'])){
            // 时间格式转为时间戳
            $mintime=strtotime($param['mintime']);
            $where[]=['o.add_time','>=',$mintime];
        }
        if (isset($param['maxtime']) && !empty($param['maxtime'])){
            $maxtime=strtotime($param['maxtime']);
            $where[]=['o.add_time','<=',$maxtime];
        }
        if (isset($param['minmoney']) && !empty($param['minmoney'])){
            $where[]=['o.goods_amount','>=',$param['minmoney']];
        }
        if (isset($param['maxmoney']) && !empty($param['maxmoney'])){
            $where[]=['o.goods_amount','<=',$param['maxmoney']];
        }


        return $where;
    }



}



?>

